interface Node {
    depth: number,
    parent: Node,
    leftChild: Node,
    rightChild: Node
}

export function rangeOfNodes (a: Node, b: Node): number {
    let range = 0;
    // 将 depth 对齐
    if (a.depth > b.depth) {
        while (b.depth < a.depth) {
            b = b.parent;
            range++;
        }
    } else {
        while (a.depth < b.depth) {
            a = a.parent;
            range++;
        }
    }

    // 一起往上找
    while (a !== b) {
        a = a.parent;
        b = b.parent;
        range += 2;
    }

    return range;
}

function sameDepth (a: Node, b: Node) {
    if (a.depth > b.depth) {
        while (b.depth < a.depth) {
            b = b.parent;
        }
    } else {

    }
}